﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using yeqw.FrameWork;
using com.gyz.hao.WinCapInfoApp.Model;

namespace com.gyz.hao.WinCapInfoApp.BLL
{
    public class CapInfoBLL
    {
        private bool InitData()
        {
            MysqlDataBLL bll = new MysqlDataBLL();
            AppConfigInfo.AppConfig.CapInfoList = bll.GetCapInfoALLList();
            if (AppConfigInfo.AppConfig.CapInfoList == null || AppConfigInfo.AppConfig.CapInfoList.Count < 1)
            {
                AppConfigInfo.AppConfig.WriteMsg("未获取到数据库数据");
                return false;
            }
            return true;

        }
        public void Exec(bool GroupCollect)
        {
            //获取数据
            if (GroupCollect == false)
            {
                if (!InitData()) return;//获取数据库中的列表数据
                AppConfigInfo.AppConfig.WriteCapMsg("启动{0}条组线程".FormatExtension(AppConfigInfo.AppConfig.GroupList.Count));
                foreach (GroupInfo group in AppConfigInfo.AppConfig.GroupList)//根据每一组来分配线程
                {
                    GroupBLL bll = new GroupBLL();
                    bll.Group = group;
                    Thread thread = new Thread(bll.Exec);//每组的线程
                    thread.Name = "group_" + group.ID;
                    thread.Start();
                }
            }
            else
            {
                if (!InitData()) return;//获取数据库中的列表数据
                AppConfigInfo.AppConfig.WriteCapMsg("启动1条组线程");
                GroupBLL bll = new GroupBLL();
                bll.Group = null;
                Thread thread = new Thread(bll.Exec);//每组的线程
                thread.Name = "group_" + 0;
                thread.Start();
            }

        }
    }
}
